#ifndef TEMPLE_THIRD_RABBIT_H_
#define TEMPLE_THIRD_RABBIT_H_

#include "config.h"
#include <thread>

class Consumer
{
public:
    Consumer();
    ~Consumer();

    struct Config
    {
        string server_host;
        int server_port;
        string vhost;
        string user_name;
        string password;
        string exchange_name;
        string exchange_type;   //direct/fanout/topic/headers
        string queue_name;
        string binding_key;
        std::function<void(string &&)> received;
    };

    int start(const Config &conf);
    void stop();

private:
    bool alive;
    std::thread *thread;
    util::Logger logger;
    Config config;
    void main_entry();
    static void entry(void *arg);
};


class Publisher
{
public:
    Publisher();
    ~Publisher();

    struct Config
    {
        string server_host;
        int server_port;
        string vhost;
        string user_name;
        string password;
        string exchange_name;
    };

    int start(const Config &conf);
    void stop();

    void send(const string &routing_key, const string &content);

private:
    bool alive;
    std::thread *thread;
    util::Logger logger;
    Config config;
    void main_entry();
    static void entry(void *arg);

    struct Message
    {
        string routing_key;
        string content;
    };
    util::Queue<Message> cache_queue;
};

#endif //TEMPLE_THIRD_RABBIT_H_
